<template>
  <div class="login-page" v-loading.fullscreen.lock="loading">
    <div class="login-box">
      <div class="login-banner-con">
        <div id="login-banner-bg"></div>
        <div id="login-banner"></div>
      </div>
      <div class="login-form-con">
        <div class="login-form-box">
          <div class="client-title">测试工具管理后台</div>
          <el-form
            ref="loginForm"
            :model="login_form"
            :rules="rules"
            label-width="1rem"
            class="flex-form-layout"
          >
            <el-form-item label="账号" prop="user_name">
              <el-input
                class="login-input-normal"
                placeholder="请输入账号"
                v-model.trim="login_form.user_name"
                @input="resetUserNameVali"
                @keyup.enter="userPressEnter"
              >
                <template #prefix>
                  <login-input-icon :state="uname_state"></login-input-icon>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="密码" prop="pwd">
              <el-input
                ref="pwdIpt"
                class="login-input-normal"
                placeholder="请输入密码"
                type="password"
                v-model="login_form.pwd"
                @input="resetPasswordVali"
                @keyup.enter="submitForm"
              >
                <template #prefix>
                  <login-input-icon icon="password" :state="pwd_state"></login-input-icon>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item class="login-btn" label-width="0">
              <el-button class="tt-btn-primary tt-login-btn" type="primary" @click="submitForm"
                >登录</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ElForm, ElInput, ElButton } from 'element-plus'
import type { FormInstance } from 'element-plus'

import { reactive, ref, toRefs } from 'vue'
import { useRouter, onBeforeRouteUpdate } from 'vue-router'
import LoginInputIcon from '@/components/iconModules/LoginInputIcon.vue'

/**
 * 表单验证
 */
const loginForm = ref<FormInstance>()
const state = reactive({
  login_form: {
    user_name: '',
    pwd: '',
  },
  uname_state: 'empty', // 标记输入框（是否有内容，是否验证通过）
  pwd_state: 'empty',
})
const { login_form, uname_state, pwd_state } = toRefs(state)
const rules = {
  user_name: [{ required: true, message: '请输入账号', trigger: 'blur' }],
  pwd: [{ required: true, message: '请输入密码', trigger: 'blur' }],
}
const resetUserNameVali = () => {
  if (state.login_form.user_name) {
    loginForm.value && loginForm.value.validateField('user_name')
  }
  if (state.login_form.user_name) {
    state.uname_state = 'not_empty'
  } else {
    state.uname_state = 'empty'
  }
}
const resetPasswordVali = () => {
  if (state.login_form.pwd) {
    loginForm.value && loginForm.value.validateField('pwd')
  }
  if (state.login_form.pwd) {
    state.pwd_state = 'not_empty'
  } else {
    state.pwd_state = 'empty'
  }
}
const resetForm = () => {
  loginForm.value && loginForm.value.resetFields()
}
/**
 * 请求跳转
 */
const router = useRouter()
const loading = ref(false)
// const store = useStore()

// 回车键识别
const pwdIpt = ref<any>()
const userPressEnter = () => {
  console.log(pwdIpt.value)
  pwdIpt.value.focus()
}
const submitForm = () => {
  console.log(state.login_form)
}
</script>

<style lang="scss" scoped>
$label-wd: 1rem;
.login-page {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  min-height: 7.02rem;
  min-width: 14.38rem;
  background-image: url('../../assets/image/login/login_BG.svg');
  background-position: left top;
}
.login-box {
  width: 13.96rem;
  height: 6.6rem;
  box-shadow: 0 0.06rem 0.21rem 0 rgba(164, 186, 238, 0.5);
  display: flex;
}
/* 左边banner */
.login-banner-con {
  width: 6.96rem;
  height: 6.6rem;
  overflow: visible;
  position: relative;
}

#login-banner-bg {
  width: 7.38rem;
  height: 7.02rem;
  background: url('../../assets/image/login/login_banner_BG.svg') no-repeat left top;
  position: absolute;
  left: -0.21rem;
  top: -0.15rem;
}
#login-banner {
  width: 6.89rem;
  height: 5.61rem;
  background: url('../../assets/image/login/login_banner.svg') no-repeat left top;
  position: absolute;
  right: 0;
  bottom: 0.04rem;
}
/* 右边form */
.login-form-con {
  width: 7rem;
  background-color: #fff;
  overflow: hidden;
  display: flex;
  justify-content: center;
}
.login-form-box {
  width: 4.4rem;
  margin-top: 1.68rem;
}
.client-title {
  font-size: 0.34rem;
  font-weight: bold;
  margin-bottom: 0.32rem;
  white-space: nowrap;
  text-align: center;
  height: 0.48rem;
  line-height: 0.48rem;
  font-family: 'PingFangSC-Medium, PingFang SC';
  color: #2141b8;
  cursor: default;
}
.login-input-normal {
  height: 0.52rem;
  margin-bottom: 0.34rem;
  border-radius: 0.26rem;
  box-shadow: 0 0.02rem 0.04rem 0 rgba(183, 202, 252, 0.48);
  ::v-deep(.el-input__wrapper) {
    border-radius: 0.26rem;
    border-color: #e4e4e4;
    line-height: 0.5rem;
    padding: 0.1rem 0.23rem;
    .el-input__inner {
      font-size: 0.24rem;
      color: #7c7c7e;
    }
    .el-input__inner::placeholder {
      color: #d1d1d1;
      font-size: 0.24rem;
    }
    .el-input__prefix-inner > :last-child {
      margin-right: 0.15rem;
    }
    // .el-input__prefix-inner span {
    //   fill:red!important;
    //   color:red!important;
    //   background-color:red;
    // }
  }
}
.tt-login-btn {
  border-radius: 0.26rem;
  height: 0.52rem;
  font-size: 0.24rem;
  font-family: 'PingFangSC-Medium, PingFang SC';
  letter-spacing: 0.3em;
  text-align: center;
  font-weight: bold;
}
.login-btn {
  margin-top: 1rem;
  .el-button {
    width: 100%;
  }
}
</style>
